package com.ybwh.springboot2.sharding5.ext.kengen;

import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.instance.InstanceContextAware;
import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;

import java.util.Properties;

/**
 * <p>
 *  对接滴滴的tinyid生成器
 * </p>
 *
 * @author fanbeibei
 * @version 1.0.0
 * @date 2023/4/12 14:46
 */
public class TinyidKeyGenerator  implements KeyGenerateAlgorithm, InstanceContextAware {

    private Properties props = new Properties();
    private volatile InstanceContext instanceContext;
    @Override
    public void init(final Properties props) {
        this.props = props;
    }

    @Override
    public Comparable<?> generateKey() {

        // 这里写 对接滴滴的tinyid  的逻辑，返回 生成的id

        return null;
    }

    @Override
    public String getType() {
        return "Tinyid";
    }

    @Override
    public boolean isDefault() {
        return false;
    }


    @Override
    public void setInstanceContext(final InstanceContext instanceContext) {
        this.instanceContext = instanceContext;
        if (null != instanceContext) {
            instanceContext.generateWorkerId(props);
        }
    }

}
